package com.hdoit.apollo.logical.cargo.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.hdoit.apollo.logical.cargo.dao.ICargoDao;
import com.hdoit.apollo.logical.cargo.mapper.CargoMapper;
import com.hdoit.apollo.logical.cargo.model.Cargo;
import com.hdoit.apollo.logical.viewmodel.cargo.CargoSearch;
import com.tennetcn.data.dao.base.ISqlExpression;
import com.tennetcn.data.dao.base.impl.SuperDao;
import com.tennetcn.data.message.PagerModel;
import com.tennetcn.data.utils.SqlExpressionFactory;
/**
 * @author      humaoshu
 * @email       
 * @createtime  2018年03月31日 15:07:34
 * @comment
 */
@Component
public class CargoDaoImpl extends SuperDao<Cargo> implements ICargoDao{
	@Autowired
	private CargoMapper cargoMapper;
	@Override
	public Cargo getCargoByCargoNo(String cargoNo, String shopId) {
		return cargoMapper.getCargoByCargoNo(cargoNo,shopId);
	}
	
	@Override
	public boolean checkCargoNo(String cargoId, String cargoNo, String shopId) {
		ISqlExpression sqlExpression = SqlExpressionFactory.createExpression();
		sqlExpression.addBody("select count(cargoId) from", Cargo.class)
					.andWhere("cargoNo=#{cargoNo}")
					.setParam("cargoNo", cargoNo)
					.andWhere("shopId=#{shopId}")
					.setParam("shopId", shopId);

		if (!StringUtils.isEmpty(cargoId)) {
			sqlExpression.andWhere("cargoId!=#{cargoId}").setParam("cargoId", cargoId);
		}
		return queryCount(sqlExpression) > 0;
	}
	
	@Override
	public boolean checkCargoNo(String cargoN) {
		return cargoMapper.checkCargoNo(cargoN)>0;
	}

	@Override
	public Cargo queryModelByCollocationId(String collocationId) {
		
		return cargoMapper.queryModelByCollocationId(collocationId);
	}

	@Override
	public List<Cargo> queryListMPForPC(CargoSearch search,
			PagerModel pagerModel) {
		
		return cargoMapper.queryListMPForPC(search,pagerModel);
	}

	@Override
	public Cargo queryModelForView(String key) {
		
		return cargoMapper.queryModelForView(key);
	}

	@Override
	public Cargo queryCargoById(String cargoId) {
		return cargoMapper.queryCargoById(cargoId);
	}

	@Override
	public boolean deleteCargoById(String cargoId) {
		ISqlExpression sqlExpression = SqlExpressionFactory.createExpression();
		sqlExpression.addBody("delete from",Cargo.class)
					.andWhere("cargoId=#{cargoId}")
					.setParam("cargoId", cargoId);
		return delete(sqlExpression)>=0;
	}

	@Override
	public Cargo getCargoByShapeCode(String shapeCode, String shopId) {
		return cargoMapper.getCargoByShapeCode(shapeCode,shopId);
	}

	@Override
	public List<Cargo> queryListMPForWechat(CargoSearch search,
			PagerModel pagerModel) {
		
		return cargoMapper.queryListMPForWechat(search,pagerModel);
	}

}